<%@ page import="com.wanmait.computershop.vo.Product" %>
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set value="${pageContext.request.contextPath}" var="path"></c:set>
<html>

	<head>
		<meta charset="UTF-8">
		<!--edge浏览器H5兼容设置-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!--360浏览器H5兼容设置-->
		<meta name="renderer" content="webkit" />
		<title>电脑商城</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!--导入核心文件-->
		<script src="/computershop/static/web/bootstrap3/js/holder.js"></script>
		<link href="/computershop/static/web/bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
		<script src="/computershop/static/web/bootstrap3/jquery-1.8.3.min.js"></script>
		<script src="/computershop/static/web/bootstrap3/js/bootstrap.js"></script>
		<!-- 字体图标 -->
		<link rel="stylesheet" href="/computershop/static/web/bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="/computershop/static/web/css/layout.css" />
		<link rel="stylesheet" type="text/css" href="/computershop/static/web/css/top.css" />
		<link rel="stylesheet" type="text/css" href="/computershop/static/web/css/footer.css" />
		<link rel="stylesheet" type="text/css" href="/computershop/static/web/css/search.css" />
		<link rel="stylesheet" type="text/css" href="/computershop/static/web/css/imgmove.css" />
		<script src="/computershop/static/web/js/search.js" type="text/javascript" charset="utf-8"></script>
		<script src="/computershop/static/web/js/imgmove.js" type="text/javascript" charset="utf-8"></script>
		
		<script type="text/javascript">
			$(function() {
				// 加入收藏时，♥的实心空心切换
				$("#add-fav-false").toggle(function() {
					var id = $(this).data("id");
					$.ajax({
						url:"/computershop/web/addFavor",
						type:"get",
						data:{pid:id}
					});
					$(this).html("<span class='fa fa-heart'></span>取消收藏");					
				}, function() {
					var id = $(this).data("id");
					$.ajax({
						url:"/computershop/web/delFavor",
						type:"get",
						data:{pid:id}
					});
					$(this).html("<span class='fa fa-heart-o'></span>加入收藏");
				});
				$("#add-fav-true").toggle(function() {
					var id = $(this).data("id");
					$.ajax({
						url:"/computershop/web/delFavor",
						type:"get",
						data:{pid:id}
					});
					$(this).html("<span class='fa fa-heart-o'></span>加入收藏");
				}, function() {
					var id = $(this).data("id");
					$.ajax({
						url:"/computershop/web/addFavor",
						type:"get",
						data:{pid:id}
					});
					$(this).html("<span class='fa fa-heart'></span>取消收藏");
				});
			});
		</script>
	</head>

	<body>
		<!--头部-->
		<jsp:include page="/WEB-INF/web/inc/header.jsp"></jsp:include>
		<!--头部结束-->
		<div class="container">
			<div class="col-md-offset-1 col-md-10"><b>${requestScope.search}</b>&nbsp;<small>搜索结果：</small></div>
			<div class="col-md-offset-1 col-md-10">
				<c:forEach items="${requestScope.searchProductList}" var="product">
					<div class="col-md-3">
						<div class="goods-panel">
							<img src="/computershop/static/web/${product.image}collect.png" class="img-responsive" />
							<p>¥${product.price}</p>
							<p class="text-row-3"><a href="/computershop/web/product?pid=${product.id}"><small>${product.title}</small></a></p>
							<span>
								<c:set var="favor" value="${true}" />
								<c:forEach items="${sessionScope.userFavorList}" var="p">
									<c:if test="${not empty p and not empty product and p.id eq product.id}">
										<c:set var="favor" value="${false}" />	
									</c:if>
								</c:forEach>
								<c:if test="${favor}">
									<a href="javascript:void(0)" id="add-fav-false" class="btn btn-default btn-xs add-fav" data-id = "${product.id}"><span class="fa fa-heart-o"></span>加入收藏</a>
								</c:if>
								<c:if test="${!favor}">
									<a href="javascript:void(0)" id="add-fav-true" class="btn btn-default btn-xs add-fav" data-id = "${product.id}"><span class='fa fa-heart'></span>取消收藏</a>
								</c:if>
								<a href="/computershop/web/cart?id=${product.id}" class="btn btn-default btn-xs add-cart"><span class="fa fa-cart-arrow-down"></span>加入购物车</a>
							</span>
						</div>
					</div>
				</c:forEach>
			</div>
		</div>			
	</body>
	<!--页脚开始-->
	<jsp:include page="/WEB-INF/web/inc/foot.jsp"></jsp:include>
	<!--页脚结束-->
</html>